package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Sms_Home_Adv_Mapper;
import com.shop.pojo.sms.Sms_Home_Adv;
import com.shop.service.Sms_Home_Adv_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图
 */
@Service
public class Sms_Home_Adv_ServiceImpl implements Sms_Home_Adv_Service {

    @Autowired
    private Sms_Home_Adv_Mapper sms_home_adv_mapper;
    /***
     * 后台显示所有轮播图
     * @param pages
     * @param sha
     * @return
     */
    @Override
    public LayuiUtils<Sms_Home_Adv> find_admin_home_adv_All(Page<Sms_Home_Adv> pages, Sms_Home_Adv sha) {
        LayuiUtils<Sms_Home_Adv> layuis = new LayuiUtils<>();
        QueryWrapper<Sms_Home_Adv> query = new QueryWrapper<>();
        if (sha.getName() != null){
            query.like("name",sha.getName());
        }
        Page<Sms_Home_Adv> sms_home_advPage = sms_home_adv_mapper.selectPage(pages, query);

        layuis.setData(sms_home_advPage.getRecords());
        layuis.setCount(sms_home_advPage.getTotal());

        return layuis;
    }

    /***
     * 后台新增轮播图
     * @param sha
     * @return
     */
    @Override
    public R insert_admin_home_adv_All(Sms_Home_Adv sha) {
        int insert = sms_home_adv_mapper.insert(sha);
        if(insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    /**
     * 后台删除轮播图
     * @param id
     * @return
     */
    @Override
    public R del_admin_home_adv_All(List<Long> id) {
        int i = sms_home_adv_mapper.deleteBatchIds(id);

        if(i > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    /**
     * 后台修改轮播图
     * @param sha
     * @return
     */
    @Override
    public R up_admin_home_adv_All(Sms_Home_Adv sha) {

        int i = sms_home_adv_mapper.updateById(sha);

        if(i > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }
}
